package com.example.schooljava.controller;


import com.example.schooljava.annotation.RequestLimit;
import com.example.schooljava.pojo.bo.AddClassBO;
import com.example.schooljava.pojo.bo.ClassBO;
import com.example.schooljava.pojo.dto.AddClassDTO;
import com.example.schooljava.pojo.dto.ClassDTO;
import com.example.schooljava.service.impl.ClassServiceImpl;
import com.example.schooljava.util.DTOtoBO;
import com.example.schooljava.util.Result;
import com.example.schooljava.util.ValidationGroups;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LDH
 * @since 2022/08/11
 */
@RestController
@RequestMapping("/school/class")
@RequestLimit(maxCount = 5,second = 2)
@Api(tags = "班级模块")
public class ClassController {
    @Autowired
    private ClassServiceImpl classService;
    @Autowired
    private DTOtoBO dtOtoBO;

    @ApiOperation(value = "添加班级",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学校管理人员添加班级")
    @PostMapping(name = "校长")
    public Result inPutClass(@RequestBody @Validated(ValidationGroups.Add.class) AddClassDTO addClassDTO){
        AddClassBO addClassBO = new AddClassBO();
        return classService.inPutClass((AddClassBO) dtOtoBO.copyPro(addClassDTO,addClassBO));
    }

    @ApiOperation(value = "获取班级",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学校管理人员获取所有班级")
    @PostMapping(value = "/getClass", name = "校长")
    public Result getClass(@RequestBody ClassDTO classDTO){
        ClassBO classBO = new ClassBO();
        return classService.getClass((ClassBO) dtOtoBO.copyPro(classDTO,classBO));
    }

    @ApiOperation(value = "删除班级",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学校管理人员删除班级，可单个可批量")
    @DeleteMapping(value = "/delClass", name = "校长")
    public Result delClass(@RequestBody ArrayList<String> list){
        return classService.delClass(list);
    }

    @ApiOperation(value = "获取空闲教师",notes = "<span style='color:red;'>详细描述：</span>&nbsp获取还未当班主任或是班级助理的教师")
    @GetMapping(value = "/teachers", name = "校长")
    public Result getTeachers(@RequestParam String teacher){
        if (Objects.equals(teacher, "headmaster"))
            return classService.getHeadmaster();
        return classService.getAssistant();
    }

    @ApiOperation(value = "修改班级",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学校管理人员修改班级信息")
    @PutMapping(value = "/edit", name = "校长")
    public Result editClass(@RequestBody @Validated(ValidationGroups.Update.class) AddClassDTO addClassDTO){
        AddClassBO addClassBO = new AddClassBO();
        return classService.editClass((AddClassBO) dtOtoBO.copyPro(addClassDTO,addClassBO));
    }

    @ApiOperation(value = "获取全部班级",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学校管理人眼获取全部班级")
    @GetMapping("/getAllClass")
    public Result getAllClass(){
        return classService.getAllClass();
    }
}
